#!/bin/bash

[[ " $* " == *" --debug "* ]] && set -x

source luf-functions.sh
load_project_config "$@"

ebegin "Check common dependencies"
eindent 1
luf_depend "$@" ; retval=$?
eoutdent 1
efinish ${retval}

# If user depend function specified run it 
if [[ $(type -t "depend") == "function" ]] ; then
    ebegin "Check project speciefic depends..."
    eindent 1
    depend "$@" ; retval=$?
    eoutdent 1
    efinish ${retval}
fi

ebegin "Initialize working directory"
eindent 1
if [[ $(type -t "init_workdir") == "function" ]] ; then
    init_workdir "$@" ; retval=$?
else
    luf_init_workdir "$@" ; retval=$?
fi
eoutdent 1
efinish ${retval}

ebegin "Copying stage image into working directory"
eindent 1
if [[ $(type -t "copy_stage") == "function" ]] ; then
    copy_stage "$@" ; retval=$?
else
    luf_copy_stage "$@" ; retval=$?
fi
eoutdent 1
efinish ${retval}

# If user stage split function specified run it 
if [[ $(type -t "install_image") == "function" ]] ; then
    ebegin "Install source image to target directory"
    eindent 1
    install_image "$@" ; retval=$?
    eoutdent 1
    efinish ${retval}
fi

# If user stage split function specified run it 
if [[ $(type -t "install_media") == "function" ]] ; then
    ebegin "Install target image to media"
    eindent 1
    install_media "$@" ; retval=$?
    eoutdent 1
    efinish ${retval}
fi
